class Solution {
public:
    vector<vector<int>> levelOrder(Node* root) {
        if (root == nullptr)
            return {};

        queue<Node*> q;
        q.push(root);
        int levelsize = 1;

        vector<vector<int>> vv;
        while (!q.empty()) {
            vector<int> tmp;
            while (levelsize) {
                Node* ret = q.front();
                q.pop();
                tmp.push_back(ret->val);
                levelsize--;
                for (auto& e : ret->children) {
                    if (e != nullptr)
                        q.push(e);
                }
            }
            levelsize=q.size();
            vv.push_back(tmp);
        }
        return vv;
    }
};